home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / edit1234.arc / EDIT1234.BAS < prev    next >
BASIC Source File  |  1991-04-28  |  12KB  |  349 lines

  1. '*************************************************
  2. 'THIS IS NOT A FUNCTIONAL PROGRAM
  3. 'It is a collection of four editors, ranging from a simple pressing the
  4. '<enter> Key to a Full feature Editor.
  5. 'Comments, Questions, Suggestions would be appreciated.  Leave Message
  6. 'for GAYLON HILL at 615-966-3574 or CompuServe 73500,2521
  7. '***************************************************
  8.  
  9. '*********************** FIRST EDITOR
  10. 'sample program  [ index.bas ] included to show how editor is used
  11. 'author George Jones
  12. DECLARE SUB OneEditScreen
  13.  
  14. EditorOne:
  15. GET #1, rn%, Alpha
  16. 'call on screen instructions, display the record, etc
  17. OneEditScreen
  18. LOCATE 16, 18: LINE INPUT New$
  19. 'if no change - press <enter> if new string is "" then string is not changed
  20. 'if new string is greater than zero then Old$ is changed to New$
  21. IF LEN(New$) <> 0 THEN Alpha.NField = New$
  22. LOCATE 16, 50: LINE INPUT NewPage$
  23. IF LEN(NewPage$) <> 0 THEN Alpha.Page = NewPage$
  24. PUT #1, rn%, Alpha
  25. 'display the edited record
  26. RETURN DispNames
  27. '********************************
  28.  
  29. '****************************EDITOR TWO - 1500 bytes
  30. 'sample program cards.bas is included to show how editor is used
  31. 'author George Jones
  32. DECLARE SUB EditorTwoOverlay ()
  33. DECLARE SUB GetKeyPress (Edit$)
  34.  
  35. EditTwo:
  36. GET #1, rn%, Easy
  37. 'call the instructions, display record to be edited, etc
  38. EditorTwoOverlay
  39. x% = 17: LOCATE x%, 6:
  40. 'How long is the string to be edited?
  41. Edit$ = Easy.Last: CALL GetKeyPress(Edit$)
  42. 'Check for Key - either <Esc> or <enter>
  43. 'if <enter> Key is pressed, accept this field as is and go to next field
  44. 'if <Esc> Key is pressed, then editor is activated - Input new data
  45. 'for first field of the record
  46. IF Edit$ <> "" THEN
  47.    LINE INPUT Easy.Last
  48.    'If new data is "zzz" then tag record and restore to file
  49.    'skip the other fields - leave them unchanged
  50.    IF LEFT$(UCASE$(Easy.Last), 3) = "ZZZ" THEN
  51.       Easy.Last = "zzz{del}" + LEFT$(Edit$, 7)
  52.       PUT #1, rn%, Easy
  53.       'display the record which is now tagged for deletion
  54.       RETURN DispName
  55.    END IF
  56. END IF
  57. LOCATE x%, 36:
  58. 'again, how long is the string to be edited
  59. Edit$ = Easy.First: CALL GetKeyPress(Edit$)
  60. 'again which key was pressed? <enter> or <Esc>
  61.    IF Edit$ <> "" THEN LINE INPUT Easy.First
  62. Spot 2, 6: Edit$ = Easy.Addr: CALL GetKeyPress(Edit$)
  63.    IF Edit$ <> "" THEN LINE INPUT Easy.Addr
  64. Spot 2, 6: Edit$ = Easy.City: CALL GetKeyPress(Edit$)
  65.    IF Edit$ <> "" THEN LINE INPUT Easy.City
  66. LOCATE x%, 31: Edit$ = Easy.State: CALL GetKeyPress(Edit$)
  67.    IF Edit$ <> "" THEN LINE INPUT Easy.State
  68. LOCATE x%, 46: Edit$ = Easy.Zip: CALL GetKeyPress(Edit$)
  69.    IF Edit$ <> "" THEN LINE INPUT Easy.Zip
  70. Spot 2, 6: Edit$ = Easy.Remk: CALL GetKeyPress(Edit$)
  71.    IF Edit$ <> "" THEN LINE INPUT Easy.Remk
  72. Easy.CarrRetn = CHR$(13) + CHR$(10)
  73. PUT #1, rn%, Easy
  74. RETURN DispName
  75.  
  76. '*********************EDITOR THREE - 1600 bytes - Similiar to Editor Four
  77. 'but smaller, with fewer functions
  78. 'author Gaylon Hill
  79. DECLARE SUB ThirdEditor (Row, Col, Text$, TextLen)
  80. CALL ThirdEditor(Row, Col, Text$, TextLen)
  81. 'documentation for this editor is included inside Sub ThirdEditor
  82. '**********************
  83.  
  84. '*********************EDITOR FOUR - 4000 bytes
  85. 'author Gaylon Hill
  86. DECLARE SUB FourthEditor (Row, Col, RCol, Text$, TextType$, TextLen, Ccode)
  87. CALL FourthEditor(Row, Col, RCol, Text$, TextType$, TextLen, Ccode)
  88. 'documentation for Fourth Editor is included inside Sub Fourth Editor
  89. '**********************
  90.  
  91. "****END OF PROGRAM, ETC*******
  92.  
  93. SUB EditorTwoOverlay
  94. Upper "T H E   E D I T   S C R E E N"
  95. x% = 3: Center 1, "To Leave an Item Unchanged, Press <enter>"
  96. Center 1, "┌┤  To Correct an Item - Press <Esc> to Enable the EDITOR;  ├┐"
  97. Center 1, "└┤then type New Data - Press <Enter> - Repeat for each Field├┘"
  98. COLOR 1, 7
  99. Center 2, "To delete this record, EDIT in " + CHR$(34) + "ZZZ" + CHR$(34) + " as Last Name and Press <enter>"
  100. Spot 3, 26: COLOR 15, 1: PRINT RTRIM$(Easy.Last); ", "; Easy.First
  101. Spot 1, 26: PRINT Easy.Addr
  102. Spot 1, 26: PRINT RTRIM$(Easy.City); ",  "; Easy.State; ",  "; Easy.Zip
  103. Spot 1, 26: PRINT Easy.Remk
  104. Spot 3, 6: COLOR 1, 7: PRINT Easy.Last: LOCATE x%, 36: PRINT Easy.First
  105. Spot 2, 6: PRINT Easy.Addr: Spot 2, 6: PRINT Easy.City;
  106. LOCATE x%, 31: PRINT Easy.State; : LOCATE x%, 46: PRINT Easy.Zip
  107. Spot 2, 6: PRINT Easy.Remk
  108. END SUB
  109.  
  110. DEFINT A-Z
  111. '
  112. SUB FourthEditor (Row, Col, RCol, Text$, TextType$, TextLen, Ccode)
  113.  
  114. 'This editor is similiar to a word processor.
  115. 'Row       = the screen row
  116. 'Col       = the screen col
  117. 'RCol      = the right far col
  118. 'Text$     = the text that is send and returned from the edit line
  119. 'TextType$ = the type of accepted text in string form
  120. '            Example: TextType$ = "0123456789". If Text$Type$ = ""
  121. '            then character 32 to 254 is accepted.
  122. 'TextLen   = the length of the Text$ to be edit
  123. 'Ccode     = returned positive number of the key that was used
  124. '            to exit the edit call
  125.  
  126.    CONST BACKSPACE = 8, TABKEY = 9, ENTER = 13, DELWORD = 20, ESC = 27
  127.    CONST DELALL = 25, DOWN = -80, HOME = -71, UP = -72, PGUP = -73
  128.    CONST LEFT = -75, RIGHT = -77, ENDKEY = -79, PGDN = -81, INS = -82
  129.    CONST DEL = -83, WORDLEFT = -115, WORDRIGHT = -116
  130.    CONST CONTROLEND = -117, CONTROLHOME = -119
  131.    CONST F1 = -59, F2 = -60, F3 = -61, F4 = -62, F5 = -63
  132.    CONST F6 = -64, F7 = -65, F8 = -66, F9 = -67, F10 = -68
  133.  
  134.    Ttext$ = LEFT$(Text$ + STRING$(TextLen, 32), TextLen)
  135.    cPos = LEN(Text$) + 1
  136.  
  137.    TRUE = 1: InSert = -1
  138.   
  139.    DO
  140.       LLen = RCol - Col
  141.       NRow = CINT(TextLen / LLen + .5)
  142.       Cr = cPos \ LLen + 1
  143.       IF Cr > 1 THEN
  144.          Cp = (cPos MOD (Cr - 1) * LLen)
  145.          IF Cp = 0 THEN
  146.             Cr = Cr - 1
  147.             Cp = LLen
  148.          END IF
  149.       ELSE
  150.          Cp = cPos
  151.       END IF
  152.       R = Row
  153.       FOR x = 1 TO NRow
  154.          LOCATE R, Col: PRINT MID$(Ttext$, x * LLen - LLen + 1, LLen);
  155.          R = R + 1
  156.       NEXT
  157.       LOCATE Row + Cr - 1, Col + Cp - 1
  158.     
  159.       DO
  160.          i$ = INKEY$
  161.       LOOP UNTIL LEN(i$)
  162.  
  163.       IF LEN(i$) = 1 THEN
  164.          KeyC = ASC(i$)
  165.       ELSE
  166.          KeyC = -ASC(RIGHT$(i$, 1))
  167.       END IF
  168.  
  169.       SELECT CASE KeyC
  170.          CASE 32 TO 254
  171.             IF INSTR(TextType$, i$) = 0 AND TextType$ <> "" THEN
  172.             ELSE
  173.                IF cPos <= TextLen AND InSert THEN
  174.                   Ttext$ = LEFT$(Ttext$, cPos - 1) + i$ + MID$(Ttext$, cPos, TextLen - cPos)
  175.                   cPos = cPos + 1
  176.                END IF
  177.                IF cPos <= TextLen AND NOT InSert THEN
  178.                   MID$(Ttext$, cPos, 1) = i$
  179.                   cPos = cPos + 1
  180.                END IF
  181.             END IF
  182.          CASE BACKSPACE
  183.             IF cPos > 1 THEN
  184.                cPos = cPos - 1
  185.                Ttext$ = LEFT$(Ttext$, cPos - 1) + MID$(Ttext$, cPos + 1, TextLen - cPos) + " "
  186.             END IF
  187.          CASE DEL
  188.             Ttext$ = LEFT$(Ttext$, cPos - 1) + MID$(Ttext$, cPos + 1, TextLen - cPos) + " "
  189.          CASE DELALL
  190.             Ttext$ = STRING$(TextLen, 32)
  191.             cPos = 1
  192.          CASE DELWORD
  193.             FOR xx = cPos TO TextLen
  194.                x$ = MID$(Ttext$, xx, 1)
  195.                IF x$ < CHR$(48) OR x$ > CHR$(122) THEN
  196.                   Ttext$ = LEFT$(Ttext$, cPos - 1) + MID$(Ttext$, xx, TextLen - xx + 1) + STRING$(xx - cPos, 32)
  197.                   EXIT FOR
  198.                END IF
  199.             NEXT
  200.             IF xx = TextLen + 1 THEN
  201.                Ttext$ = LEFT$(Ttext$, cPos - 1) + STRING$(TextLen - cPos + 1, 32)
  202.             END IF
  203.             IF xx = cPos THEN
  204.                Ttext$ = LEFT$(Ttext$, cPos - 1) + MID$(Ttext$, cPos + 1, TextLen - cPos) + " "
  205.             END IF
  206.          CASE ENDKEY
  207.             FOR xx = TextLen TO 1 STEP -1
  208.                IF MID$(Ttext$, xx, 1) > CHR$(32) THEN
  209.                   cPos = xx + 1
  210.                   EXIT FOR
  211.                END IF
  212.             NEXT
  213.          CASE CONTROLEND, CONTROLHOME, ESC, PGDN, PGUP, TABKEY, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10
  214.             GOTO ExitRoutine
  215.          CASE ENTER
  216.             Cr = (cPos / LLen + .5)
  217.             cPos = Cr * LLen + 1
  218.             IF cPos > TextLen THEN
  219.                GOTO ExitRoutine
  220.             END IF
  221.          CASE UP
  222.             cPos = cPos - LLen
  223.             IF cPos < 1 THEN
  224.                GOTO ExitRoutine
  225.             END IF
  226.          CASE DOWN
  227.             cPos = cPos + LLen
  228.             IF cPos > TextLen THEN
  229.                GOTO ExitRoutine
  230.             END IF
  231.          CASE HOME
  232.             cPos = 1
  233.          CASE INS
  234.             InSert = NOT InSert
  235.          CASE LEFT
  236.             IF cPos > 1 THEN
  237.                cPos = cPos - 1
  238.             END IF
  239.          CASE RIGHT
  240.             IF cPos < TextLen THEN
  241.                cPos = cPos + 1
  242.             END IF
  243.          CASE WORDLEFT
  244.             IF cPos > 1 THEN
  245.                FOR xx = cPos - 1 TO 1 STEP -1
  246.                   IF MID$(Ttext$, xx, 1) > CHR$(32) THEN
  247.                      sw = 1
  248.                   END IF
  249.                   IF sw = 1 AND MID$(Ttext$, xx, 1) = CHR$(32) THEN
  250.                      cPos = xx + 1: sw = 0
  251.                      EXIT FOR
  252.                   END IF
  253.                NEXT
  254.                IF xx = 0 THEN
  255.                   cPos = 1: sw = 0
  256.                END IF
  257.             END IF
  258.          CASE WORDRIGHT
  259.             FOR xx = cPos TO TextLen
  260.                IF MID$(Ttext$, xx, 1) = CHR$(32) THEN
  261.                   sw = 1
  262.                END IF
  263.                IF sw = 1 AND MID$(Ttext$, xx, 1) > CHR$(32) THEN
  264.                   cPos = xx: sw = 0
  265.                   EXIT FOR
  266.                END IF
  267.             NEXT
  268.          CASE ELSE
  269.       END SELECT
  270.    LOOP WHILE TRUE
  271.  
  272. ExitRoutine:
  273.    Ccode = ABS(KeyC)
  274.    Text$ = RTRIM$(Ttext$)
  275.  
  276. END SUB
  277.  
  278. DEFSNG A-Z
  279. SUB GetKeyPress (Edit$)
  280. x% = CSRLIN
  281. p% = POS(0)
  282. ss% = LEN(Edit$)
  283. LOCATE x%, p%: COLOR 7, 0: PRINT Edit$
  284. LOCATE x%, p%
  285. DO
  286.    K$ = INKEY$
  287.    IF K$ = CHR$(13) THEN
  288.       COLOR 0, 7: PRINT Edit$
  289.       Edit$ = ""
  290.       EXIT SUB
  291.    END IF
  292. LOOP WHILE K$ <> CHR$(27)
  293.    IF K$ = CHR$(27) THEN
  294.       COLOR 15, 4: PRINT SPACE$(ss%)
  295.       LOCATE x%, p%, 1
  296.    END IF
  297. END SUB
  298.  
  299. SUB OneEditScreen
  300. COLOR 0, 1, 8: CLS : Upper "T H E   E D I T   S C R E E N"
  301. Center 2, "To accept NAME, or PAGE, as written, Press <enter>"
  302. Center 2, "To CORRECT either NAME  or PAGE , re-type entry and Press <enter>"
  303. Center 2, "To DELETE this record - Type " + CHR$(34) + "ZZZ" + CHR$(34) + " for Name and Press <enter> "
  304. Spot 2, 15: COLOR 15, 4: PRINT " E d i t i n g   R e c o r d   N u m b e r"
  305. LOCATE x%, 60: COLOR 15, 0: PRINT rn%
  306. Spot 2, 18: COLOR 0, 2: PRINT "N A M E "
  307. LOCATE x%, 50: PRINT "P A G E"
  308. Spot 2, 18: COLOR 0, 7: PRINT Alpha.NField;
  309. LOCATE x%, 50: COLOR 1, 7: PRINT Alpha.Page
  310. END SUB
  311.  
  312. DEFINT A-Z
  313. '
  314. SUB ThirdEditor (Row, Col, Text$, TextLen)
  315.  
  316. 'Row       = the screen row
  317. 'Col       = the screen col
  318. 'Text$     = the text that is send and returned from the edit line
  319. 'TextLen   = the length of the Text$ to be edit
  320.  
  321.    DO
  322.       LOCATE Row, Col: PRINT Text$;
  323.       LOCATE Row, Col + cPos - 1
  324.  
  325.       DO
  326.          KeyC$ = INKEY$
  327.       LOOP UNTIL LEN(KeyC$)
  328.           
  329.       SELECT CASE ASC(KeyC$)
  330.          CASE 32 TO 254
  331.             IF cPos <= TextLen THEN
  332.                MID$(Text$, cPos, 1) = KeyC$
  333.                cPos = cPos + 1
  334.             END IF
  335.          CASE 8
  336.             IF cPos > 1 THEN
  337.                cPos = cPos - 1
  338.                Text$ = LEFT$(Text$, cPos - 1) + MID$(Text$, cPos + 1, TextLen - cPos) + " "
  339.             END IF
  340.          CASE 13
  341.             LOCATE , , 0
  342.             Text$ = RTRIM$(Text$)
  343.             EXIT SUB
  344.       END SELECT
  345.    LOOP
  346.  
  347. END SUB
  348.  
  349.